define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'line/index' + location.search,
                    add_url: 'line/add',
                    edit_url: 'line/edit',
                    del_url: 'line/del',
                    multi_url: 'line/multi',
                    import_url: 'line/import',
                    table: 'line',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                showExport:false,//去掉导出
                // search:false,//去掉ID搜索
                // commonSearch:false,//去掉放大镜
                // showToggle:false,//去掉切换
                // showColumns:false,//去掉列
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'line_name', title: __('Line_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'sharing_price', title: __('Sharing_price'), operate:'BETWEEN'},
                        {field: 'all_price', title: __('All_price'), operate:'BETWEEN'},
                        {field: 'start_station', title: __('Start_station'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'end_station', title: __('End_station'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'way', title: __('Way'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'switch', title: __('Switch'), searchList: {"0":__('Switch 0'),"1":__('Switch 1')}, table: table, formatter: Table.api.formatter.toggle},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        // {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons:[
                                {
                                    name: 'station',
                                    title: '线路站点管理',
                                    icon: 'fa fa-bars',
                                    text: '站点',
                                    url: 'linestation/index',
                                    classname: 'btn btn-info btn-xs btn-execute btn-dialog',
                                    extend: 'data-area=\'["90%", "90%"]\'',
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
